<?php

class Application_Model_Academic
{
     protected $_dbTable;


    public function getdbTable() {
         if (null === $this->_dbTable) {
            $this->setDbTable('Application_Model_DbTable_Academic');
        }
        return $this->_dbTable;
    }

    public function setdbTable($dbTable) {
        if (is_string($dbTable)) {
            $dbTable = new $dbTable();
        }
        if (!$dbTable instanceof Zend_Db_Table_Abstract) {
            throw new Exception('Invalid table data gateway provided');
        }
        $this->_dbTable = $dbTable;
        return $this;
    }

    public function save($data)
    {
        return $this->getdbTable()->insert($data);
    }

  	/*
  	 *
  	 *  Retrives all class existing in the school
  	 */
    public function fetchAll()
    {
        $db = Zend_Registry::get ( 'db' );
	$stmt = $db->query ( "Select  id , DATE_FORMAT(start_date,'%b,%D %Y') as start_date ,DATE_FORMAT(end_date,'%b,%D %Y') as end_date  from academic " );
    	return  $stmt->fetchAll();
    }

    public function getCurrentAcademicYearId()
    {

         $db = Zend_Registry::get ( 'db' );
         $query = "SELECT  id , DATE_FORMAT(start_date,'%b,%D %Y') AS start_date ,DATE_FORMAT(end_date,'%b,%D %Y') AS end_date  FROM academic WHERE DATEDIFF(`start_date`,CURRENT_DATE) >= 0 AND DATEDIFF(CURRENT_DATE,`end_date`) <= 0";
	 $stmt = $db->query ( $query );
    	return  $stmt->fetch();
    }

}

